package com.zyy.joseata.advice;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;

/**
 * @author zhangyy
 */
public class AnnotationInterceptor implements MethodInterceptor {

    @Override
    public Object invoke(MethodInvocation methodInvocation) throws Throwable {
        // 在目标方法执行前执行的逻辑
        System.out.println("Before advice: Before executing method " + methodInvocation.getMethod().getName());

        // 调用目标方法
        Object result = methodInvocation.proceed();

        // 在目标方法执行后执行的逻辑
        System.out.println("After advice: After executing method " + methodInvocation.getMethod().getName());

        return result;
    }
}
